1. Field
The present disclosure relates to resource management of a multi-threaded system by controlling when thread state is stored to memory and, more specifically, to attempting to increase the speed in which task switching occurs by controlling whether or not thread state stored to memory.
2. Background Information
Many programming languages, operating systems, and other software development environments support what are called “threads” of execution. Threads are often similar to processes, in that both usually represent a single sequence of instructions executed in parallel with other sequences, either by time slicing or multiprocessing. Threads are often a way for a program to split itself into two or more simultaneously running tasks. For example, a common use of threads is having one thread paying attention to the graphical user interface, while others do a long calculation in the background. As a result, the application more readily responds to user's interaction.
Threads are usually distinguished from traditional multi-tasking processes in that processes are typically independent, carry considerable state information, and interact only through system-provided inter-process communication mechanisms. Multiple threads, on the other hand, typically share the state information of a single process, share memory and other resources directly. On operating systems that have special facilities for threads, it is typically faster for the system to context switch between different threads in the same process than to switch between different processes.
An advantage of a multi-threaded program may be that it can operate faster on computer systems that have multiple CPUs, or across a cluster of machines. This is because the threads of the program often naturally lend themselves for truly concurrent execution.
A context switch is the computing process of storing and restoring the state of a processor (the context) such that multiple processes can share a single processor resource. The context switch is an essential feature of a multitasking operating system. Context switches are usually computationally intensive and much of the design of operating systems is to optimize the use of context switches.
Context switches usually involve the following steps, assuming process P1 is running on the processor and process P2 is the next process to run on the processor:
First, the execution of P1 is halted.
Second, the context of P1 is stored somewhere in memory (usually on the stack of P1, or on the operating-system defined thread information structure). The context of the processor will typically contain the value of registers such as the program counter, processor control and general purpose registers.
Third, the context of P2 is retrieved from memory (usually on the stack of P2, or on the system structure associated with P2).
Finally, processing begins from the location contained in the program counter (the line of code at which P2 was interrupted).
Context switches are costly due to the fact that no actual process execution occurs while the state of the first process is stored and the state of the second process is loaded. If the processes contains a large number of threads (i.e. the processes are multi-threaded) the amount of state information needed to be saved and loaded may be large.
The amount of time needed to save the state information is generally limited by the amount of bandwidth available on the memory bus. For example, if the processor can only save X-bits per processor clock cycle via the memory bus and the state information needed to be saved is 10,000X-bits, the processor will not be able to execute any process instructions for at least 10,000 clock cycles, as the context switch between the two processes occurs. A need therefore exists to decrease the amount of time wasted during a context switch.